# qa_system.py
from EmbeddingStorageModule import EmbeddingStorageModule
from PromptEngineerModule import PromptEngineerModule
from agent2 import EnterpriseAgentSystem
from debug import DebugCallbackHandler, TaskChainModule

def run_qa_system(faiss_index_path="faiss_index"):
    print("初始化提示词工程...")
    prompt_engineering = PromptEngineerModule()

    print("初始化任务链模块和回调处理函数...")
    callback_handler = DebugCallbackHandler()
    task_chain = TaskChainModule(callback_handler=callback_handler)

    print("初始化企业级Agent系统...")
    enterprise_agent = EnterpriseAgentSystem(faiss_index_path=faiss_index_path)

    print("问答系统已启动，输入 'exit' 结束循环问答")
    while True:
        query = input("请输入问题：")
        if query.lower() in ["exit", "quit"]:
            print("退出问答系统")
            break

        print("生成提示词模板...")
        prompt = prompt_engineering.create_prompt_template(query=query)
        print("提示词模板生成成功")

        print("执行任务链模块...")
        task_chain_result = task_chain.execute_task_chain(query)
        print("任务链结果:", task_chain_result)

        print("执行Agent系统模块...")
        agent_response = enterprise_agent.execute_query(query, user_react=True)
        print("Agent响应:", agent_response)

        # 可选：查看回调日志
        # log_file = callback_handler.log_file
        # print(f"回调日志存储路径: {log_file}")

if __name__ == "__main__":
    run_qa_system()
